<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置套接字为阻塞模式</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.socket-sendto.html">« socket_sendto</a></li>
      <li style="float: right;"><a href="function.socket-set-nonblock.html">socket_set_nonblock »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.sockets.html">Socket 函数</a></li>
    <li>设置套接字为阻塞模式</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.socket-set-block" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_set_block</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">socket_set_block</span> &mdash; <span class="dc-title">设置套接字为阻塞模式</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-set-block-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>socket_set_block</strong></span>(<span class="methodparam"><span class="type"><a href="class.socket.html" class="type Socket">Socket</a></span> <code class="parameter">$socket</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>socket_set_block()</strong></span> 函数移除了由 <code class="parameter">socket</code> 
   参数定义的 <strong><code>O_NONBLOCK</code></strong> 标记。
  </p>
  <p class="para">
   当一个操作（例如接收、发送、连接、接受连接……）在一个阻塞套接字上执行时，脚本在接受到信号或者可以执行此操作前将暂停执行。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-set-block-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       由 <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span> 或 <span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span> 
       创建的 <span class="classname"><a href="class.socket.html" class="classname">Socket</a></span> 实例。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-set-block-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.socket-set-block-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
  <td>8.0.0</td>
  <td>
   现在 <code class="parameter">socket</code> 是 <span class="classname"><a href="class.socket.html" class="classname">Socket</a></span> 实例，
   之前是 <span class="type">resource</span>。
  </td>
 </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.socket-set-block-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4506">
    <p><strong>示例 #1 <span class="function"><strong>socket_set_block()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$socket&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">socket_create_listen</span><span style="color: #007700">(</span><span style="color: #0000BB">1223</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">socket_set_block</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">socket_accept</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     此示例在 1223 端口上创建了监听所有接口的套接字，并把此套接字设置为 <strong><code>O_BLOCK</code></strong> 
     模式。<span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span> 将挂起，直到接受新的连接。
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-set-block-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.socket-set-nonblock.html" class="function" rel="rdfs-seeAlso">socket_set_nonblock()</a> - 设置套接字为非阻塞模式</span></li>
    <li class="member"><span class="function"><a href="function.socket-set-option.html" class="function" rel="rdfs-seeAlso">socket_set_option()</a> - 为套接字设置套接字选项</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>